public class practice {
    class Solution {
        public String minWindow(String ss, String tt) {
            int kinds=0;
            int len=Integer.MAX_VALUE;
            int begin=-1;
            char[] s=ss.toCharArray();
            char[] t=tt.toCharArray();
            int[]hash1=new int[128]; //用于统计字符串中字符的频次
            int[]hash2=new int[128];
            for(char ch:t) {
                if(hash1[ch]==0){
                    kinds++;
                }
                hash1[ch]++;
            }
            for(int left=0,right=0,count=0;right<s.length;right++){
                char in=s[right];
                hash2[in]++;
                if(hash1[in]==hash2[in]){
                    count++;
                }
                while(count==kinds){
                    if(right-left+1<len){
                        len=right-left+1;
                        begin=left;
                    }
                    char out=s[left++];
                    if(hash1[out]==hash2[out]){
                        count--;
                    }
                    hash2[out]--;

                }
            }
            if(begin==-1){
                return new String();
            }

            return ss.substring(begin,begin+len);


        }
    }
}
